package com.crazy.web.controller;

import com.crazy.logs.Logger;
import com.crazy.model.major.dto.UserSession;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author zhaochaofeng
 * @version 1.0
 * @date 2020/11/17 15:22
 */
@Slf4j
@Controller
public class IndexController extends BaseController{

    @GetMapping({"/index", "/", "/login"})
    public String index() {
        UserSession userSession = getUserSession();
        log.info("{}用户正在使用{}请求", MDC.get(Logger.REQUEST_IP), MDC.get(Logger.TIRACE_ID_KEY));
        if (userSession == null) {
            return "login";
        }else{
            return "index";
        }
    }

    /**
     * 跳转的相应的错误页面，code代表相应的页面
     * @param code
     * @return
     */
    @GetMapping("/error/{code}")
    public String error(@PathVariable("code") String code) {
        return "error/"+code;
    }

}
